package com.yizhubao.app.presenters;

import com.yizhubao.app.base.BasePresenter;
import com.yizhubao.app.base.BaseResultBean;
import com.yizhubao.app.models.SaveRecordModel;
import com.yizhubao.app.models.WelfareModel;
import com.yizhubao.app.utils.net.BaseObserver;
import com.yizhubao.app.views.SaveRecordView;
import com.yizhubao.app.views.WelfareView;

import java.util.Map;

/**
 * @author Pacy.
 * Date: 2021/6/9/009
 * Time: 21:17
 * Mail pengwwe457621023@qq.com
 * Info 保存记录
 */
public class WelfarePresenter extends BasePresenter<WelfareView> {
    private WelfareModel model;

    public WelfarePresenter() {
        model = new WelfareModel();
    }

    public void sendRequest(Map<String, Object> map) {
        model.saveWelfareRequest(map, new BaseObserver() {
            @Override
            public void onSuccess(BaseResultBean t) {
                if (isViewAttached()) {
                    getView().onSaveSuccess(t.isSuccess());
                }
            }

            @Override
            public void onError(String errMessage) {
                if (isViewAttached()) {
                    getView().showFailure(errMessage);
                }
            }

            @Override
            public void onComplete() {
                super.onComplete();
                if (isViewAttached()) {
                    getView().showFinished();
                }

            }
        }, getView().getLifeSubject());
    }
}
